package com.dsteiner.widgets.client;


import java.util.ArrayList;
import java.util.List;

import com.dsteiner.widgets.client.Widgets.FlowPanelExt;
import com.dsteiner.widgets.client.Widgets.HTMLExt;
import com.dsteiner.widgets.client.Widgets.HorizontalPanelExt;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.controller.PaginationController;
import com.dsteiner.widgets.client.model.PaginationModel;
import com.dsteiner.widgets.client.resources.WidgetsResources;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;

public class PaginationWidget extends LazyWidget {

	private PaginationController paginationController = new PaginationController();
	private final PaginationModel paginationModel;

	public PaginationWidget(PaginationModel paginationModel) {
		this.paginationModel = paginationModel;
	}

	@Override
	public Widget createContentWidget() {
		HorizontalPanel mainPanel = new HorizontalPanel();
		HorizontalPanelExt pagePanel = new HorizontalPanelExt();
		HTMLExt resultsHtml = new HTMLExt();
		HTMLExt prevLink = new HTMLExt("<a href=\"javascript:void(0);\">&lt;ANTERIOR</a>");
		HTMLExt nextLink = new HTMLExt("<a href=\"javascript:void(0);\">PROXIMO></a>");
		ListBoxWidget itemsPerPageListBox = new ListBoxWidget();
		FlowPanelExt pagesContentPanel = new FlowPanelExt();
		
		itemsPerPageListBox.addItem("10");
		itemsPerPageListBox.addItem("25");
		itemsPerPageListBox.addItem("50");
		itemsPerPageListBox.addItem("100");
		
		List<String> items = new ArrayList<String>();
		List<String> values = new ArrayList<String>();
		items.add("10 por pagina");
		items.add("25 por pagina");
		items.add("50 por pagina");
		items.add("100 por pagina");
		
		values.add("10");
		values.add("25");
		values.add("50");
		values.add("100");
		
		itemsPerPageListBox.setItems(items, values);
		
		mainPanel.add(pagePanel);
		mainPanel.add(resultsHtml);
		mainPanel.add(itemsPerPageListBox);
		
		pagePanel.add(new HTML("<strong>pagina:</strong>"));
		pagePanel.add((Widget)prevLink);
		pagePanel.add((Widget)pagesContentPanel);
		pagePanel.add((Widget)nextLink);
		
		setStyleName(WidgetsResources.INSTANCE.css().paginationWidget());
		pagesContentPanel.setStyleName(WidgetsResources.INSTANCE.css().pagesContentPanel());
		resultsHtml.addStyleName(WidgetsResources.INSTANCE.css().resultsHtml());
		paginationController.registerPaginationWidget(this);
		paginationController.registerPaginationModel(paginationModel);
		paginationController.registerPagesContentPanel(pagesContentPanel);
		paginationController.registerPrevLink(prevLink);
		paginationController.registerNextLink(nextLink);
		paginationController.registerPagePanel(pagePanel);
		paginationController.registerItemsPerPageListBox(itemsPerPageListBox);
		paginationController.registerResultsHtml(resultsHtml);
		
		return mainPanel;
	}

}